#pragma once

#ifndef ROOT_TGTab
#include <TGTab.h>
#endif

#ifndef ROOT_TGTextEntry
#include <TGTextEntry.h>
#endif

#ifndef ROOT_TGButton
#include <TGButton.h>
#endif

#include <TGTextEdit.h>

#include <vector>

#include <TGFileDialog.h>
#include "CalibOptions.h"

#define SYNC_ID 1
#define CHOOSE_ID 1

class ConfigTab
{
public:
	ConfigTab(void);
	~ConfigTab(void);

	void Create( TGTab *fDataTabCalibTab, void * appPtr );

	bool ShowRawResults() {return Selected(m_showRawResults);};
        bool PrintIntegrals() {return Selected(m_printIntegrals);};
        bool DrawOscilograms() {return Selected(m_drawSignals);};
        bool UseBgCalib() {return Selected(m_useBgCalib);};
        bool UseStatWeight() {return Selected(m_useStatWeight);};
        bool UseFilters() {return Selected(m_useFilers);};
        bool UseTimeSync() {return Selected(m_sync);};
        bool AutoChooseChanels() {return Selected(m_autoChoose);};

        std::vector<bool> GetChanelStates();
        std::vector<std::string> GetShots(calib_type type);

        void SyncChanged(Int_t id)
        {
            if( SYNC_ID == id )
                m_autoChoose->SetEnabled(true);
            else
            {
                m_autoChoose->SetState(kButtonUp);
                m_autoChoose->SetEnabled(false);
                
                if( m_manualChoose->GetState() == kButtonUp )
                    for( int i = 0; i < m_useChanel.size(); ++i )
                        m_useChanel[i]->SetEnabled(true);

                m_manualChoose->SetState(kButtonDown);
                
            }
        };

        void ChoiseModeChanged(Int_t id)
        {
            if( CHOOSE_ID == id )
                for( int i = 0; i < m_useChanel.size(); ++i )
                    m_useChanel[i]->SetEnabled(false);
            else
                for( int i = 0; i < m_useChanel.size(); ++i )
                    m_useChanel[i]->SetEnabled(true);
        }

        calib_options GetCalibOpts(calib_type type);
        void NormToSecPeak();
        void BrowseArc();
        std::string GetArcName();

private:

        bool Selected(TGButton *check)
        {
            if( check->GetState() == kButtonDown )
                return true;
            else
                return false;
        }

	std::vector<TGCheckButton *> m_useChanel;

        TGCheckButton *m_useBgCalib;
        TGCheckButton *m_useStatWeight;
        TGCheckButton *m_useFilers;
        
        TGCheckButton *m_drawSignals;
        TGCheckButton *m_printIntegrals;
        TGCheckButton *m_showRawResults;

        TGRadioButton *m_sync;
        TGRadioButton *m_autoChoose;
        TGRadioButton *m_manualChoose;

        TGCompositeFrame *t_fCompositeFrame979 ;

        TGTextEdit *m_bgShots;
        TGTextEntry *m_peakArc;
        TGTextEdit *m_peakShots;

        TGRadioButton *m_normToCustomChanel;
        TGRadioButton *m_normToSum;
        TGRadioButton *m_additionalNorm;
        
        TGCheckButton *m_normToSecPeak;

        TGTextButton *m_calibratePeak;
        TGTextButton *m_browse;
};

